<template>
  <div class="addFeed" :style="'height:' + height + 'px;'">
    <div>
      <HeadTop :title="headTitle"></HeadTop>
      <div class="head-time">{{new Date | format}}</div>
    </div>
    <div class="addClass">
      <div class="addClass-title">生物信息</div>
      <div class="addClass-line"></div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物名称</div>
        <div class="addFeed-con-msg">
          <van-dropdown-menu>
            <van-dropdown-item v-model="value" :options="opt" />
          </van-dropdown-menu>
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">计量单位</div>
        <div v-if="opt[value]">
          <input class="addFeed-con-msg" :value="opt[value].measurement" disabled />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物单价</div>
        <div>
          <input class="addFeed-con-msg" v-model="biologyUnitPrice" @keyup="getBiologyTotalPrice" />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物数量</div>
        <div>
          <input class="addFeed-con-msg" v-model="biologyQuantity " @keyup="getBiologyTotalPrice" />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">总价</div>
        <div>
          <input class="addFeed-con-msg" v-model="biologyTotalPrice " disabled />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">区域</div>
        <div>
          <input class="addFeed-con-msg" v-model="deathArea " />
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">死亡类型</div>
        <div class="addFeed-con-msg">
          <van-dropdown-menu>
            <van-dropdown-item v-model="value2" :options="opt2" />
          </van-dropdown-menu>
        </div>
      </div>
    </div>
    <div class="addClass-btn">
      <div class="addClass-btn-hold" @click="submit(0)">保存</div>
      <div class="addClass-btn-submit" @click="submit(1)">提交</div>
    </div>

  </div>
</template>
<script>
import {
  getBiologyList,
  insertBiologyStatisticsReport,
  getDeathTypeList
} from '../../../../api/index.js'
import HeadTop from '../../../../components/headTop.vue'
import {
  getYYYYMMDD
} from '../../../../api/unit.js'
export default {
  data () {
    return {
      headTitle: '死亡统计报表添加',
      value: 0,
      value2: 0,
      opt: [],
      opt2: [],
      height: document.documentElement.clientHeight,
      biologyUnitPrice: '',
      biologyQuantity: '',
      biologyTotalPrice: void 0,
      deathArea: ''

    }
  },
  filters: {
    format: function (value) {
      return getYYYYMMDD(value).nTime
    }
  },
  async mounted () {
    let msg = await getBiologyList()
    let idx = 0
    msg.data.map(v => {
      v.text = v.biologyName
      v.value = idx
      idx++
    })
    this.opt = msg.data
    this.value = msg.data[0].value
    msg = await getDeathTypeList()
    idx = 0
    msg.data.map(v => {
      v.text = v.deathType
      v.value = idx
      idx++
    })
    this.opt2 = msg.data
    this.value2 = msg.data[0].value
  },
  methods: {
    getBiologyTotalPrice () {
      if (this.biologyUnitPrice === '' || this.biologyQuantity === '') {
        this.biologyTotalPrice = ''
      } else {
        this.biologyTotalPrice = (this.biologyUnitPrice * 100) * (this.biologyQuantity * 100) / 10000
      }
    },
    async submit (v) {
      if (this.biologyQuantity === '') {
        this.$notify({
          type: 'danger',
          message: '请输入生物数量'
        })
        return
      }
      if (this.biologyUnitPrice === '') {
        this.$notify({
          type: 'danger',
          message: '请输入生物单价'
        })
        return
      }
      if (this.deathArea === '') {
        this.$notify({
          type: 'danger',
          message: 'deathArea'
        })
        return
      }
      let data = {
        medictionId: this.opt[this.value].id,
        biologyQuantity: this.biologyQuantity,
        biologyUnitPrice: this.biologyUnitPrice,
        deathArea: this.deathArea,
        deathTypeId: this.opt2[this.value2].id,
        submit: v
      }
      let result = await insertBiologyStatisticsReport(data)
      if (result.code === 10000) {
        this.$router.go(-1)
      } else {
        this.$notify({
          type: 'danger',
          message: result.msg
        })
      }
    }
  },
  components: {
    HeadTop
  }
}
</script>

<style scoped>
  .addFeed {
    background: #e5e5e5;
  }

  .head-time {
    width: 750px;
    height: 109px;
    background: #fff;
    border-top: #e5e5e5 2px solid;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
  }

  .addClass {
    background: #fff;
    width: 686px;
    border-top: #e5e5e5 solid 17px;
    padding: 40px 32px;
    font-size: 32px;
    overflow: hidden;
  }

  .addClass-title {
    padding-bottom: 40px;
    font-weight: bold;
    margin-left: 5px;
  }

  .addClass-line {
    background-color: #e5e5e5;
    height: 1px;
    width: 686px;
  }

  .addFeed-con {
    display: flex;
    font-size: 28px;
    color: #757575;
    height: 45px;
    line-height: 45px;
    margin-top: 34px;
  }

  .van-dropdown-menu {
    height: 45px;
    background: #f9f9f8;
    text-align: left;

  }

  .addFeed-con-name {
    width: 150px;
    margin-left: 12px;
  }

  .addFeed-con-msg {
    padding: 0 25px;
    width: 485px;
    background: #f9f9f8;
  }

  .addClass-title-text {
    width: 675px;
    background: #FBF8F9;
    line-height: 54px;
    border: 1px solid #e5e5e5;
  }

  .addClass-btn {
    width: 750px;
    background: #e5e5e5;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 154px;
    font-size: 32px;
  }

  .addClass-btn-hold {
    width: 332px;
    height: 111px;
    line-height: 111px;
    text-align: center;
    background: #fff;
    font-weight: bold;
    color: #999;
  }

  .addClass-btn-submit {
    width: 332px;
    height: 111px;
    line-height: 111px;
    text-align: center;
    color: #009EEA;
    background: #fff;
    font-weight: bold;
  }
</style>
